﻿#region copyright
//<copyright>
// Copyright(C) 2012 TrackerRealm Corporation
// This file is part of the open source project - Jazz. http://jazz.codeplex.com
// 
// Jazz is open software: you can redistribute it and/or modify it 
// under the terms of the GNU Affero General Public License (AGPL) as published by 
// the Free Software Foundation, version 3 of the License.
// 
// Jazz is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty 
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
//  See the GNU Affero General Public License (AGPL) for more details.
// 
// You should have received a copy of the GNU General Public 
// License along with Jazz.  If not, see <http://www.gnu.org/licenses/>.
//
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT. 
//</copyright>
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using TrackerRealm.Jazz.Common;
using C = TrackerRealm.Jazz.Common.JazzConstants;

// namespace will change for this class
namespace TrackerRealm.Jazz.Client.Custom
{
    /// <summary>
    /// A workspace is simalar to a directory in a file system.
    /// A Workspace contains workflows including other workspaces.
    /// All workflow must belong to a single workspace.
    /// </summary>
    [Root]
    [Jazz]
    [UseEmptyObjectFor(typeof(jWorkspaceBase))]
    public class jWorkspace:jWorkspaceBase
    {
        #region PublicID
        /// <summary>
        /// The ID for the workspace with the name 'Public'. 
        /// </summary>
        public static readonly Guid PublicID = new Guid("ACC45367-0D6E-4CB5-8958-E082648E73CA");
        #endregion
        #region EmptyID
        /// <summary>
        /// The ID for the 'Empty' Workspace.
        /// </summary>
        public static readonly Guid EmptyID = new Guid("88FDA117-86C4-4694-8184-751807921390");
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public new readonly static jWorkspace[] EmptyArray = new jWorkspace[0];
        //
        // Factory Methods 
        //
        #region CreateEmpty
        /// <summary>
        /// Creates an Empty Workspace.
        /// </summary>
        /// <returns></returns>
        public static jWorkspace CreateEmpty()
        {
            jWorkspace ws = jWorkspace.Create(C.WORKSPACE_EMPTY);
            return ws;
        }
        #endregion
        #region Create a Workspace (string name)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static jWorkspace Create(string name)
        {
            return new jWorkspace(name);
        }
        #endregion
        #region Create a Workspace (ClientNexus nexus, string name)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="nexus"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static jWorkspace Create(ClientNexusBase nexus, string name)
        {
            return new jWorkspace(nexus, name);
        }
        #endregion
        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name"></param>
        protected jWorkspace(string name)
        :base(name)
        {
        }
        #endregion
        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nexus"></param>
        /// <param name="name"></param>
        private jWorkspace(ClientNexusBase nexus, string name)
            : base(nexus, name)
        {
           
        }
        #endregion

        #region IsPartiallyCached
        /// <summary>
        /// 
        /// </summary>
        public bool IsPartiallyCached
        {
            get { return base._IsPartiallyCached; }
            internal set { base._IsPartiallyCached = value; }
        }
        #endregion
        #region Assign Fixed Ids.
        /// <summary>
        /// Assigns a fixed ID to the 'Guest' user.
        /// </summary>
        /// <returns></returns>
        protected internal override Guid OnAssignID()
        {
            if (this.Name == C.WORKSPACE_PUBLIC)
                return jWorkspace.PublicID;
            else if (this.Name == C.WORKSPACE_EMPTY)
                return jWorkspace.EmptyID;
            else
                return base.OnAssignID();
        }
        #endregion
        #region Move
        /// <summary>
        /// Moves the specified jazzObject to be a child of this workspace.
        /// </summary>
        /// <param name="jazzObject"></param>
        public void Move(jObject jazzObject)
        {
            base._Move(jazzObject);
        }
        #endregion
        #region ACL -Add/Remove
        /// <summary>
        /// The ACL (Access Control List) controls how this '<see cref="jObject"/>' instance
        /// can be accessed.
        /// <para>Note: If the ACL sequence is empty then there are no access restrictions.</para>
        /// </summary>
        public IEnumerable<jAclItem> ACL
        {
            get { return base._ACL; }
        }
        /// <summary>
        /// Add a '<see cref="jAclItem"/>' to this jObject's ACL.
        /// </summary>
        /// <param name="item"></param>
        public void Add(jAclItem item)
        {
            base._AddACL(item);
        }
        /// <summary>
        /// Remove a '<see cref="jAclItem"/>' from this jObject's ACL.
        /// </summary>
        /// <param name="item"></param>
        public void Remove(jAclItem item)
        {
            base._RemoveACL(item);
        }
        #endregion
    }
}
